ST Trend Line Finder 9000
https://gyazo.com/f2ef2b3e249f1e7ef880972ba2aa83ed
https://gyazo.com/016c818b6b74c1b1f628d7e0c2699847 https://jp.tradingview.com/script/z5skEEoQ-ST-Trend-Line-Finder-9000/
code:ST Trend Line Finder 9000(js) //@version=2
study("ST Trend Line Finder 9000", overlay=true) //I like tips :D
//look back distance
shortl = input(20)
longl = input(100)
//establish timeline in bars
timeline = nz(timeline1) + 1 //find bottoms
middle = round(1) //half way through shortl round(shortl/2)
//a = valuewhen(lowmiddle==lowest(low, shortl), lowmiddle, 0) //what is lowest point in the short range //whena = valuewhen(lowmiddle==lowest(low, shortl), fixnan(timelinemiddle), 0) //when is lowest point in the range whena = valuewhen(lowmiddle==lowest(low, shortl), fixnan(timelinemiddle), 0) middlelong = round(longl/2)
//b= valuewhen(fixnan(lowmiddle)==lowest(low, shortl) , fixnan(lowmiddle), 1) // //whenb = valuewhen(fixnan(lowmiddle)==lowest(low, shortl) , timelinemiddle, 1) // whenb := b==a? valuewhen(fixnan(lowmiddlelong)==lowest(low, longl) , fixnan(timelinemiddlelong), 1) : whenb //m = ((b-a)/(whenb-whena))
//trendprice = m*(timeline-whena-0) + a
//backtrendprice = m*(timeline-whena-middle) + a
m = (((b)-(a))/(whenb-whena))
trendprice = (m*(timeline-whena-0)) + a
backtrendprice = (m*(timeline-whena-middle)) + a
sametrend = a==fixnan(a1) and b==fixnan(b1) and a!=0 and b!=0 and whena!=whenb //plot
plot(sametrend? trendprice: na, style=linebr, color=green, linewidth=2, offset=0, transp=50)
plot(sametrend? backtrendprice: na, style=linebr, color=green, linewidth=1, offset=-middle, transp=50)
forwardtrendprice = (m*(timeline-whena+middle)) + a
plot(sametrend? forwardtrendprice: na, style=linebr, color=green, linewidth=1, offset=middle, transp=70)
//find tops
a2 = valuewhen(highmiddle==highest(high, shortl), highmiddle, 0) // whena2 = valuewhen(highmiddle==highest(high, shortl), timelinemiddle, 0) // b2 := b2==a2? valuewhen(fixnan(highmiddlelong)==highest(high, longl) , fixnan(highmiddlelong), 1) : b2 whenb2 := b2==a2? valuewhen(fixnan(highmiddlelong)==highest(high, longl) , fixnan(timelinemiddlelong), 1) : whenb2 m2 = ((b2-a2)/(whenb2-whena2))
trendprice2 = m2*(timeline-whena2-0) + a2
backtrendprice2 = m2*(timeline-whena2-shortl) + a2
sametrend2 = a2==fixnan(a21) and b2==fixnan(b21) and a2!=0 and b2!=0 and whena2!=whenb2 //plot
plot(sametrend2? trendprice2:na, style=linebr, color=red, linewidth=2, offset=-0, transp=50)
plot(sametrend2? backtrendprice2:na, style=linebr, color=red, linewidth=1, offset=-shortl, transp=50)
forwardtrendprice2 = (m2*(timeline-whena2+middle)) + a2
plot(sametrend2? forwardtrendprice2: na, style=linebr, color=red, linewidth=1, offset=middle, transp=70)
こっちは参考(コード非公開)
https://gyazo.com/077a9fa993b3d0297b769eb73cee5f8a https://www.tradingview.com/script/BEkhTXb2-Auto-trendline-Spicytrader-ASCENDING/